
params ["_pos", "_num", "_level", "_dis", "_type", ["_water", false]];

private["_pos_tar", "_group", "_num0", "_num1", "_num2", "_num3"];


if(_water) then{
	_pos_tar = _pos getPos[_dis * (Param_EnemySpawnDis + 0.3), random 360];
}else{
	_pos_tar = [_pos, _dis * (Param_EnemySpawnDis + 0.3), 50] call fn_getPosNearLand;
};
//


//创建小队
switch (_type) do
{
	case 0:{_group = createGroup resistance;};
	case 1:{_group = createGroup resistance};
	case 2:{_group = createGroup resistance};
	case 3:{_group = createGroup west};
	case 4:{_group = createGroup east};
	case 5:{_group = createGroup civilian};
	default {_group = createGroup west};
};

if(Param_Debug == 1) then
{
	_group addGroupIcon ["b_inf",[0,0]];
	switch (side _group) do
	{
		case west:{_group setGroupIconParams [[0,0,1,1],"北约",1,true];};
		case east:{_group setGroupIconParams [[1,0,0,1],"358团",1,true];};
		case resistance:{_group setGroupIconParams [[0,1,0,1],"中立",1,true];};
		case civilian:{_group setGroupIconParams [[1,0,1,1],"平民",1,true];};
		default {_group setGroupIconParams [[1,1,1,1],"未知",1,true];};
	};
};



_num = _num * Param_EnemySpawnNum * call fn_aiNum;


if(!surfaceIsWater _pos_tar) then
{
	//_____________________________创建守卫_____________________________
	_num3 = 0;
	switch (_level) do
	{
		case 1:{_num0 = _num * 0.70; _num1 = _num * 0.25; _num2 = _num * 0.05};
		case 2:{_num0 = _num * 0.60; _num1 = _num * 0.30; _num2 = _num * 0.10};
		case 3:{_num0 = _num * 0.50; _num1 = _num * 0.37; _num2 = _num * 0.13};
		case 4:{_num0 = _num * 0.40; _num1 = _num * 0.42; _num2 = _num * 0.18};
		case 5:{_num0 = _num * 0.30; _num1 = _num * 0.45; _num2 = _num * 0.23; _num3 = _num * 0.10};
		case 6:{_num0 = _num * 0.20; _num1 = _num * 0.50; _num2 = _num * 0.28; _num3 = _num * 0.20};
	};
	
	//轻型
	for "_i" from 1 to (ceil _num0) do
	{
		switch (_type) do
		{
			case 0:{[selectRandom asu_i_c_0, _pos_tar, 0, _group] call fn_createUnit};
			case 1:{[selectRandom asu_i_g_0, _pos_tar, 0, _group] call fn_createUnit};
			case 2:{[selectRandom asu_i_0, _pos_tar, 0, _group] call fn_createUnit};
			case 3:{[selectRandom asu_b_0, _pos_tar, 0, _group] call fn_createUnit};
			case 4:{[selectRandom asu_o, _pos_tar, 0, _group] call fn_createUnit};
		};
	};
	//中型
	for "_i" from 1 to (ceil _num1) do
	{
		switch (_type) do
		{
			case 0:{[selectRandom asu_i_c_1, _pos_tar, 1, _group] call fn_createUnit};
			case 1:{[selectRandom asu_i_g_1, _pos_tar, 1, _group] call fn_createUnit};
			case 2:{[selectRandom asu_i_1, _pos_tar, 1, _group] call fn_createUnit};
			case 3:{[selectRandom asu_b_1, _pos_tar, 1, _group] call fn_createUnit};
			case 4:{[selectRandom asu_o, _pos_tar, 0, _group] call fn_createUnit};
		};
	};
	//重型
	for "_i" from 1 to (ceil _num2) do
	{
		switch (_type) do
		{
			case 0:{[selectRandom asu_i_c_2, _pos_tar, 2, _group] call fn_createUnit};
			case 1:{[selectRandom asu_i_g_2, _pos_tar, 2, _group] call fn_createUnit};
			case 2:{[selectRandom asu_i_2, _pos_tar, 2, _group] call fn_createUnit};
			case 3:{[selectRandom asu_b_2, _pos_tar, 2, _group] call fn_createUnit};
			case 4:{[selectRandom asu_o, _pos_tar, 0, _group] call fn_createUnit};
		};
	};
	if(_type != 4) then
	{
		//固定武器
		for "_i" from 1 to (ceil _num3) do
		{
			private _unit_support = [selectRandom asu_support, _pos_tar, 3, _group] call fn_createUnit;
			_unit_support spawn fn_runSupport; 
		};
		
		//海军不加入VcomAi
		_group spawn fn_squadAI;
	};
}
else
{
	private ["_boat", "_boat_num", "_boat_type"];
	
	//概率为大船
	if(random 100 < 25)then{_level = 5};
	
	//先创建船
	if(_level >= 5) then
	{
		if(Param_RHS == 1)then{
			_boat_type = "rhsusf_mkvsoc";
		}else{
			_boat_type = "I_Boat_Armed_01_minigun_F";
		};
	}
	else
	{
		_boat_type = "C_Boat_Transport_02_F";
	};
	
	private _boat_num = ceil(_num / 12); 
	//移动到船
	for "_i" from 1 to _boat_num do
	{
		_boat = _boat_type createVehicle _pos_tar; 
		_boat enableDynamicSimulation true;
		
		for "_j" from 1 to 8 do
		{
			_unit = [selectRandom asu_boat, _pos_tar, 4, _group] call fn_createUnit;
			_unit moveInAny _boat;
		};
	};
	
	if(_level < 5) then
	{
		[_group, _boat] spawn
		{
			private _group = _this select 0;
			private _boat = _this select 1;
			while{true} do
			{
				sleep 12;
				if(isNull _boat
				|| {!alive _boat}
				|| {isNull _group}
				|| {count (units _group) == 0})  exitWith{};
				
				if(getTerrainHeightASL(getPos _boat) > -5) exitWith
				{
					//所有人下车
					{ unassignVehicle _x } forEach crew _boat; crew _boat allowGetIn false;
				};
			};
			
			//deleteVehicle _boat;
		};
	};
	

};


_group enableDynamicSimulation true;


_group
